package com.kgc.basicprovider.controller;

import com.kgc.basic.pojo.Store;
import com.kgc.basic.pojo.Unit;
import com.kgc.basic.remote.UnitRemote;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.basicprovider.service.StoreService;
import com.kgc.basicprovider.service.UnitService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UnitController implements UnitRemote {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UnitService unitService;

    @Override
    public ResponseMsg getUnitList(@RequestBody Map<String, Object> paramMap) {
        logger.info("UnitController getUnitList paramMap:"+paramMap);
        ResponseMsg msg = unitService.getUnitList(paramMap);
        logger.debug("UnitController getUnitList msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg getAllUnit() {
        logger.info("UnitController getAllUnit is start");
        ResponseMsg msg = unitService.getAllUnit();
        logger.debug("UnitController getAllUnit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg getUnitById(@RequestParam("id") Integer id) {
        logger.info("UnitController getUnitById id:"+id);
        ResponseMsg msg = unitService.getUnitById(id);
        logger.debug("UnitController getUnitById msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg getUnitByName(@RequestParam("name") String name) {
        logger.info("UnitController getUnitByName name:"+name);
        ResponseMsg msg = unitService.getUnitByName(name);
        logger.debug("UnitController getUnitByName msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg addUnit(@RequestBody Unit unit) {
        logger.info("UnitController addUnit unit:"+unit);
        ResponseMsg msg = unitService.addUnit(unit);
        logger.debug("UnitController addUnit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg modifyUnit(@RequestBody Unit unit) {
        logger.info("UnitController modifyUnit unit:"+unit);
        ResponseMsg msg = unitService.modifyUnit(unit);
        logger.debug("UnitController modifyUnit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg delUnit(@RequestParam("id") Integer id) {
        logger.info("UnitController delUnit id:"+id);
        ResponseMsg msg = unitService.delUnit(id);
        logger.debug("UnitController delUnit msg:"+msg);
        return msg;
    }
}
